package com.vsoft.sms_cm;

import java.io.DataOutputStream;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;

import org.apache.log4j.Logger;

import com.vsoft.framework.core.BaseException;
import com.vsoft.framework.core.BusiObj;
import com.vsoft.framework.core.Configuration;
import com.vsoft.framework.core.db.DBGadgets;
import com.vsoft.framework.core.db.DBTrans;
import com.vsoft.framework.core.esb.ServiceBus;
import com.vsoft.framework.core.util.BOHelper;
import com.vsoft.framework.core.util.LogCollect;
import com.vsoft.framework.core.util.XMLUtil;
import com.vsoft.framework.server.servlet.SessionData;
import com.vsoft.framework.server.servlet.HttpUtil;
import com.vsoft.anti_fra.*;

public class TestCacheMode {

	private static Logger vLogger = Logger.getLogger(TestGetStatic.class);
	private static String vName = TestGetStatic.class.getName();
	private SessionData vSD = null;
	private String vDebugHome = "";
	private BusiObj				vInBO		=  new BusiObj();
	
	
	public static void main(String[] args)  {
	
		try{

			vLogger.info("---------------InitSystem-------------");
			Configuration.InitSystem();
			vLogger.info("---------------generate test data-------------");
			Connection conn = DBTrans.getConnection();
			BusiObj bo=new BusiObj() ;
			TableCacheServer.setDebugFlag("1");
			
			TableCacheServer.init(conn);
		//TableCacheServer.init(conn);
		//特服号码：4002169666
					bo.setString("order_num", "05503084030");// 05503084030（两个模板：企业编码10009，100009）
			//05512690095  短信模板未审核    05662023940  cdr_type=3
			//05512683516  短信模板无群组
					//05513659663
			bo.setString("mobile_num", "13973284157");//白名单15305669789  普通电话：18955179099
			int cnt=0;
			for(int i =0;i<=1;i++)
			{
				for (int j=1;j<=3;j++)
				{
					cnt++;
					vLogger.info("===========test   i="+i+"       j="+j +"      cnt="+cnt);
					//特服号码：4002169666
					bo.setString("order_num", "05503084030");// 05503084030（两个模板：企业编码10009，100009）
					bo.setString("mobile_num", "15305669020");//白名单15305669789  普通电话：18955179099
					bo.setString("cdr_type", String.valueOf(j));
					bo.setConnection(conn);
					bo=TableCacheServer.getTempleForSend(bo);
					//vLogger.info("返回数据是:\n\n\n\n" + BOHelper.boToXML(bo));
				}
				
			}
/*			bo.setString("cdr_type", "3");//
			bo.setConnection(conn);
			bo=TableCacheServer.getTempleForSend(bo);
			vLogger.info("返回数据是:\n\n\n\n" + BOHelper.boToXML(bo));
			
			bo.setConnection(conn);
//			bo.setString("order_num", "05513659663");// 05503084030（两个模板：企业编码10009，100009）
			bo.setString("ent_code", "67");//10006
			TableCacheServer.refreshCallNumber(bo);*/
			
	/*		bo.setConnection(conn);
			bo.setString("order_num", "05662020861");//
			bo.setString("mobile_num", "13973284157");//白名单15305669789  普通电话：18955179099
			bo.setString("cdr_type", "1");//
			bo=TableCacheServer.getTempleForSend(bo);
			vLogger.info("返回数据是:\n\n\n\n" + BOHelper.boToXML(bo));
			
			bo.setConnection(conn);
			bo.setString("order_num", "05662020861");//
			bo.setString("mobile_num", "13973284157");//白名单15305669789  普通电话：18955179099
			bo.setString("cdr_type", "2");//
			bo=TableCacheServer.getTempleForSend(bo);
			vLogger.info("返回数据是:\n\n\n\n" + BOHelper.boToXML(bo));
			
			bo.setConnection(conn);
			bo.setString("order_num", "05662020861");//
			bo.setString("mobile_num", "13973284157");//白名单15305669789  普通电话：18955179099
			bo.setString("cdr_type", "3");//
			bo=TableCacheServer.getTempleForSend(bo);
			vLogger.info("返回数据是:\n\n\n\n" + BOHelper.boToXML(bo));*/
			//TableCacheServer.refreshTriggerPhone(bo);
			bo.setConnection(conn);
			bo.setString("ent_code", "1037792");//10006  101460
			TableCacheServer.refreshCallNumber(bo);
			//特服号码：4002169666
			bo.setString("order_num", "13973301234");// 05503084030（两个模板：企业编码10009，100009）
			bo.setString("mobile_num", "15305669020");//白名单15305669789  普通电话：18955179099
			bo.setString("cdr_type","1");
			bo.setConnection(conn);
			bo=TableCacheServer.getTempleForSend(bo);
			vLogger.info("返回数据是:\n\n\n\n" + BOHelper.boToXML(bo));
			////////////////////////退订
			BusiObj inBO	= new BusiObj();
			inBO.setString("sys_src", "1");
			inBO.setString("area_no", "");//0566
			inBO.setString("order_num", "13973301234");//2288888  5112391  （0564 2610111）  3659658
			inBO.setString("debugsee", "1");
			inBO.setString("new_flag", "1");
			inBO.setConnection(conn);
			inBO.setName("BizSU");
			inBO.setString("SESSION_STAFF_NO", "999");
			
			BusiObj retBo					=		ServiceBus.runService(inBO);
			vLogger.info("退订---------返回数据是:\n\n\n\n" + BOHelper.boToXML(retBo));
			///////////////////////////////////////////刷新触发电话 
			bo.setConnection(conn);
			bo.setString("ent_code", "1037792");//10006  101460
			TableCacheServer.refreshTriggerPhone(bo);
			///////////////////////////////////////////重新查询
			bo.setString("order_num", "13973301234");// 05503084030（两个模板：企业编码10009，100009）
			bo.setString("mobile_num", "15305669020");//白名单15305669789  普通电话：18955179099
			bo.setString("cdr_type","1");
			bo.setConnection(conn);
			bo=TableCacheServer.getTempleForSend(bo);
/*			bo.setConnection(conn);
			bo.setString("ent_code", "101398");//10006
			vLogger.info("==============ent_code:101398" );
			TableCacheServer.refreshCallNumber(bo);
			
			bo.setConnection(conn);
			bo.setString("ent_code", "10023342");//10006
			vLogger.info("==============ent_code:10023342" );
			TableCacheServer.refreshCallNumber(bo);
			bo.setString("order_num", "05573697652");// 05503084030（两个模板：企业编码10009，100009）
			bo.setString("mobile_num", "15305669020");//白名单15305669789  普通电话：18955179099
			bo.setString("cdr_type","1");
			bo.setConnection(conn);
			bo=TableCacheServer.getTempleForSend(bo);*/
	//		Customer customer = new Customer();10023342 0557 3697652

/*			StaticBO.setString("cdr_type", "4");
			StaticBO.setString("order_num", "05503084030");// 05512681039 白名单：888
			StaticBO.setString("mobile_num", "18955179099");//
			StaticBO	=	customer.getCalledSMSTemple(StaticBO);*/
			vLogger.info("返回数据是:\n\n\n\n" + BOHelper.boToXML(bo));
		        //DBGadgets.check(conn);
			conn.rollback();
			//conn.commit();
			conn.close();
			//vLogger.info("返回数据是:\n\n\n\n" + BOHelper.boToXML(retBo));


		}
		catch(SQLException e)
		{
			e.printStackTrace();
		}
		catch(BaseException e)
		{
			e.printStackTrace();
			vLogger.error(e.ErrMethod);
			vLogger.error(e.SysMsg);
		}
			vLogger.info("---------------Game Over-------------");
	}	

		

	private int  init()
	{
		int iRet = 0;
		vSD = new  SessionData();
		vSD.vRoleCode = new String[] {"1"};
		vSD.vStaffCode = "1";
		vSD.vStaffNo = "0001";
		vSD.vStaffName = "test";
		
	
		vDebugHome = System.getProperty("DEBUG_HOME");
		if (vDebugHome == null)
		{
			iRet = -1;
			vLogger.error("需要设置DEBUG_HOME环境变量来指定debug 文件所在的目录");
		}
		return iRet;
		
	}
	
}
